#include <cstdio>
using namespace std;
 
int S[30005];
 
int getf(int x) {
    if (S[x] == x) return x;
    return S[x] = getf(S[x]);
}
 
void merge(int x, int y) {
    int xf = getf(x), yf = getf(y);
    if (xf != yf) {
        S[xf] = S[yf];
    }
}
 
int main() {
    int n, m, p, a, b, first;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i) {
        S[i] = i;
    }
    for (int i = 1; i <= m; ++i) {
    	scanf("%d %d", &p, &first);
        for (int j = 1; j < p; ++j) {
        	scanf("%d", &b);
        	merge(first, b);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (getf(i) == getf(0)){
        	++ans;
        	//printf("%d ", i);
        } 
	}
	//printf("\n");
	printf("%d\n", ans);
    return 0;
}
